
import 'package:flutter/material.dart';


class DemoPage extends StatelessWidget {
  const DemoPage({Key key }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Demo页面"),
      ),
      body: const DemoWidget(),
    );
  }
}

class DemoWidget extends StatefulWidget {
  const DemoWidget({Key key}) : super(key: key);

  @override
  State<DemoWidget> createState() => _DemoWidgetState();
}

class _DemoWidgetState extends State<DemoWidget> {


  String btnText = "test";


  @override
  Widget build(BuildContext context) {
    print("------_DemoWidgetState--------build");
    return Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            ElevatedButton(
              onPressed: (){
                setState(() {
                  if(btnText == "test"){
                    btnText = "测试";
                  }else{
                    btnText = "test";
                  }
                });
              },
              child: Text(btnText),
            ),
            ElevatedButton(
              onPressed: (){
                print("返回......");
                Navigator.of(context).pop();
              },
              child: const Text("返回"),
            ),
          ],
        ),
    );
  }
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    print("------_DemoWidgetState--------initState");
  }

  @override
  void didChangeDependencies() {
    // TODO: implement didChangeDependencies
    super.didChangeDependencies();
    print("-------_DemoWidgetState-------didChangeDependencies");
  }

  @override
  void setState(VoidCallback fn) {
    // TODO: implement setState
    super.setState(fn);
    print("------_DemoWidgetState--------setState");
  }

  @override
  void deactivate() {
    // TODO: implement deactivate
    super.deactivate();
    print("------_DemoWidgetState--------deactivate");
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    print("-----_DemoWidgetState---------dispose");
  }
}
